package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Category;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface CategoryMapper {
    @Insert("INSERT INTO category VALUES (null,#{type},#{name},#{sort},#{createTime},#{updateTime},#{createUser},#{createUser});")
    void save(Category category);

    @Select("SELECT * FROM category ORDER BY sort")
    List<Category> findByPage();

    @Delete("DELETE FROM category WHERE id = #{id};")
    void delete(Long id);

    @Update("UPDATE category SET type=#{type},name=#{name},sort=#{sort},update_time=#{updateTime},update_user=#{updateUser} WHERE id = #{id};")
    void update(Category category);

    List<Category> list(@Param("type") Integer type);

    @Select("SELECT * FROM category WHERE id =#{id}")
    Category findById(Long categoryId);
}
